﻿#include "n2base.h"
#ifndef COFF_H_EDA52EEC8EB52486
#define COFF_H_EDA52EEC8EB52486  1

typedef struct
{
    char            name[8];
    n2u32           virtual_size;   // not used in .obj
    n2u32           virtual_addr;   // not used in .obj
    n2u32           raw_size;
    n2u32           raw_offset;
    n2u32           relinfo_offset;
    n2u32           linenum_offset;
    n2u16           relinfo_count;
    n2u16           linenum_count;
    n2u32           flag;
}Coff32_Shdr;

#define COFF_SECTION_HEADER_SIZE                (40)

#define COFF_SYMBOL_ENTRY_SIZE                          (18)

#define COFF_AUX_SYM_TYPE_FUNCTION_DEF                  1
#define COFF_AUX_SYM_TYPE_FUNCTION_BF_EF                2
#define COFF_AUX_SYM_TYPE_FUNCTION_WEAK                 3
#define COFF_AUX_SYM_TYPE_FUNCTION_FILE                 4
#define COFF_AUX_SYM_TYPE_FUNCTION_SECTION_DEF          5
#define COFF_AUX_SYM_TYPE_FUNCTION_CLR                  6

#define COFF_SYM_CLASS_EXTERNAL                         2
#define COFF_SYM_CLASS_STATIC                           3
#define COFF_SYM_CLASS_FUNCTION                         101
#define COFF_SYM_CLASS_FILE                             103
#define COFF_SYM_CLASS_WEAK                             105

#define COFF_SYM_EXT_TYPE_GLOBAL                        0
#define COFF_SYM_EXT_TYPE_COMDAT                        1
#define COFF_SYM_EXT_TYPE_WEAK                          2
#define COFF_SYM_EXT_TYPE_COMMON                        3
#define COFF_SYM_EXT_TYPE_STATIC                        4

typedef struct
{
    char                name[8];
    unsigned int        value;
    unsigned short      section_id;
    unsigned short      type;
    unsigned char       storage_class;
    unsigned char       aux_count;
}Coff32_Symb;

typedef struct
{
    unsigned int        TagIndex;
    unsigned int        TotalSize;
    unsigned int        PointerToLinenumber;
    unsigned int        PointerToNextFunction;
    unsigned char       noused[2];
}Coff32_AuxSymFuncDef;

typedef struct
{
    unsigned char       noused1[4];
    unsigned short      Linenumber;
    unsigned char       noused2[6];
    unsigned int        PointerToNextFunction;
    unsigned char       noused3[2];
}Coff32_AuxSymFuncBfEf;

typedef struct
{
    unsigned int        TagIndex;
    unsigned int        Characteristics;
    unsigned char       noused[10];
}Coff32_AuxSymWeak;

typedef union
{
    unsigned char       FileName[18];
    struct {
        unsigned int    zero;
        unsigned int    offset;
        unsigned char   noused[10];
    }info;
}Coff32_AuxSymFile;

typedef struct
{
    unsigned int        Length;
    unsigned short      NumberOfRelocations;
    unsigned short      NumberOfLinenumbers;
    unsigned int        CheckSum;                   // only use for COMDAT
    unsigned short      Number;
    unsigned char       Selection;
    unsigned char       Unused[3];
}Coff32_AuxSymSectionDef;

typedef struct
{
    unsigned char       bAuxType;
    unsigned char       bReserved;
    unsigned char       bSymbolTableIndex[4];
    unsigned char       Unused[12];
}Coff32_AuxSymClr;

typedef union {
    Coff32_Symb             base;
    Coff32_AuxSymFuncDef    funcdef;
    Coff32_AuxSymFuncBfEf   funcbfef;
    Coff32_AuxSymWeak       weakinfo;
    Coff32_AuxSymFile       file;
    Coff32_AuxSymSectionDef sectiondef;
    Coff32_AuxSymClr        clrinfo;
}Coff32Symbol;


#endif // COFF_H_EDA52EEC8EB52486


